// pages/welcome/launch.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const _ = this;
    let redirectUrl = options.redirectUrl;
    app.loginReady = function (timestamp) {
      _.toPage(redirectUrl, timestamp);
    }
  },
  toPage: function (redirectUrl, timestamp){
    const { user } = app.globalData;
    let url = '';
    if (redirectUrl){
      url = decodeURIComponent(redirectUrl);
    }else{
      let type = '';
      if (user.userType == 1) type = 'factory';
      if (user.userType == 2) type = 'order';
      url = `/pages/home/home?type=${type}`;
      if (user.userType == 0 || user.authStatus != 2) {
        url = '/pages/welcome/welcome'
      }
    }
    // url = "/packageUser/pages/auth/auditting";
    wx.reLaunch({
      url: url
    })
  }
})